package com.redbox.RedboxManagment.controllers;



import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;
import com.redbox.RedboxManagment.ejb.Card;
import com.redbox.RedboxManagment.ejb.User;
import com.redbox.RedboxManagment.service.ICardPaymentService;
import com.redbox.RedboxManagment.service.ICardService;
import com.redbox.RedboxManagment.service.IUserService;

/**
 * Handles requests for the application home page.
 */
@Controller
@SessionAttributes("user")
public class HomeController {
	
	private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
	
	@Autowired
	private ICardService cardService;
	
	@Autowired
	private IUserService userService;
		
	@Autowired
	private ICardPaymentService cardPaymentService;
	
	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping(value = "**/home", method = RequestMethod.GET)
	@Transactional
	public ModelAndView home (Locale locale,Model model,@ModelAttribute("user") User user,HttpServletRequest request) {
		
		ModelAndView x = new ModelAndView();
		x.setViewName("home");
		Card card = cardService.retrieveCard(2);
		x.addObject("card", card);
		x.addObject("user",user);
			
		return x;
	}
	
}
